package indi.zhifa.core.multidatasource.core;

import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;

import javax.sql.DataSource;

public class ZfRoutingDataSource extends AbstractRoutingDataSource {

    ThreadLocal<String> curDbKey = new ThreadLocal<String>();

    @Override
    protected Object determineCurrentLookupKey() {
        return curDbKey.get();
    }

    public String curKey(){
        return curDbKey.get();
    }

    public void set(String pKey) {
        curDbKey.set(pKey);
    }

    public void clear() {
        curDbKey.remove();
    }

    public DataSource getTargetDataSource() {
        return determineTargetDataSource();
    }
}
